﻿using System;
using System.Security.Cryptography;
using System.Text;

namespace BlackoutRugby.encriptador
{
    class Encriptador
    {
        public static string encriptar(string cadenaAEncriptar, long idEquipo)
        {
            // Create an unencrypted request as an array of bytes
            byte[] request = null;

            if (idEquipo == 82565)
                request = UTF8Encoding.UTF8.GetBytes("dk=vCHnfy02aNyTJPjK&m=110862&mk=60400689f5d1d03b8284d1025ec0dee04f0af03c" + cadenaAEncriptar);
            else if (idEquipo == 83074)
                request = UTF8Encoding.UTF8.GetBytes("dk=vCHnfy02aNyTJPjK&m=114107&mk=60400689f5d1d03b8284d1025ec0dee04f0af03c" + cadenaAEncriptar);
            else if (idEquipo == 82899)
                request = UTF8Encoding.UTF8.GetBytes("dk=vCHnfy02aNyTJPjK&m=114344&mk=60400689f5d1d03b8284d1025ec0dee04f0af03c" + cadenaAEncriptar);
            else
                request = UTF8Encoding.UTF8.GetBytes("");
            // Set the dev ID
            //string devID = "508";

            // Set the key and IV as arrays of bytes
            byte[] key = UTF8Encoding.UTF8.GetBytes("vCHnfy02aNyTJPjK");
            byte[] iv = UTF8Encoding.UTF8.GetBytes("i6PkWc2hFyvLXuDY");

            // Create an instance of the AES Encryptor
            AesCryptoServiceProvider aes = new AesCryptoServiceProvider();

            // Set the key and IV
            aes.Key = key;
            aes.IV = iv;

            // Set the mode of the AES Encryptor
            aes.Mode = CipherMode.CBC;

            // Set the padding mode of the AES Encryptor
            aes.Padding = PaddingMode.Zeros;

            // Get the transformer from the AES Encryptor
            ICryptoTransform cTransform = aes.CreateEncryptor();

            // Use the transformer to encrypt our request
            byte[] result =
              cTransform.TransformFinalBlock(request, 0, request.Length);

            // Release resources held by AES Encryptor
            aes.Clear();

            // Encode to base64
            string cadenaEncriptada =
              Convert.ToBase64String(result, 0, result.Length);

            return cadenaEncriptada;
            
        }
    }
}
